package com.sz.common.pay.pingan.util;

import com.sz.common.pay.pingan.constant.Constant;
import com.sz.common.pay.pingan.constant.ResponseCode;
import com.sz.common.pay.pingan.exception.PayCommonException;

import java.io.UnsupportedEncodingException;

/**
 * Function: 编码转换器 <br>
 *
 * @author: siqishangshu <br>
 * @date: 2017-12-20 10:36:00
 */
public class CharSetUtil {

    public static byte[] getBytesFromStringToGBK(String tranMessage) throws PayCommonException {
        try {
            return tranMessage.getBytes(Constant.CHARSET_GBK);
        } catch (UnsupportedEncodingException e) {
            PayExceptionUtil.throwPayCommonException("编码转换错误 " + e.getMessage(), ResponseCode.ERR947);
        }
        return null;
    }

    public static String getStringFromBytesToGBK(byte[] bRspCode) throws PayCommonException {
        try {
            return new String(bRspCode, Constant.CHARSET_GBK);
        } catch (UnsupportedEncodingException e) {
            PayExceptionUtil.throwPayCommonException("编码转换错误 " + e.getMessage(), ResponseCode.ERR947);
        }
        return null;
    }
}
